
#include "nx_api.h"

#ifdef __PRODUCT_NETXDUO__

#include "netx_mdns_test.h"

/* Frame (90 bytes) */
static const unsigned char pkt1[90] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x00, 0x4c, 0x00, 0x07, 0x40, 0x00, 0xff, 0x11, /* .L..@... */
0x90, 0x5c, 0x0a, 0x00, 0x00, 0x42, 0xe0, 0x00, /* .\...B.. */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x38, /* .......8 */
0x46, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* F....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x5f, /* ......._ */
0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x04, /* printer. */
0x5f, 0x73, 0x75, 0x62, 0x05, 0x5f, 0x68, 0x74, /* _sub._ht */
0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, /* tp._tcp. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, /* local... */
0x00, 0x01                                      /* .. */
};

/* Frame (199 bytes) */
static const unsigned char pkt2[199] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0xec, 0x17, /* ..^..... */
0x2f, 0xbd, 0xa4, 0xb1, 0x08, 0x00, 0x45, 0x00, /* /.....E. */
0x00, 0xb9, 0x1d, 0xbb, 0x00, 0x00, 0xff, 0x11, /* ........ */
0xf4, 0xca, 0xc0, 0xa8, 0x07, 0x0a, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0xa5, /* ........ */
0x3b, 0x23, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, /* ;#...... */
0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x08, 0x5f, /* ......._ */
0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x04, /* printer. */
0x5f, 0x73, 0x75, 0x62, 0x05, 0x5f, 0x68, 0x74, /* _sub._ht */
0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, /* tp._tcp. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, /* local... */
0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x07, /* ........ */
0x04, 0x74, 0x65, 0x73, 0x74, 0xc0, 0x1a, 0x08, /* .test... */
0x43, 0x61, 0x74, 0x72, 0x6f, 0x2d, 0x50, 0x43, /* Catro-PC */
0xc0, 0x25, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, /* .%...... */
0x00, 0x78, 0x00, 0x04, 0xc0, 0xa8, 0x07, 0x0a, /* .x...... */
0xc0, 0x36, 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, /* .6.!.... */
0x00, 0x78, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, /* .x...... */
0x00, 0x50, 0xc0, 0x3d, 0xc0, 0x36, 0x00, 0x10, /* .P.=.6.. */
0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x01, /* ........ */
0x00, 0xc0, 0x3d, 0x00, 0x2f, 0x80, 0x01, 0x00, /* ..=./... */
0x00, 0x00, 0x78, 0x00, 0x05, 0xc0, 0x3d, 0x00, /* ..x...=. */
0x01, 0x40, 0xc0, 0x36, 0x00, 0x2f, 0x80, 0x01, /* .@.6./.. */
0x00, 0x00, 0x00, 0x78, 0x00, 0x09, 0xc0, 0x36, /* ...x...6 */
0x00, 0x05, 0x00, 0x00, 0x80, 0x00, 0x40        /* ......@ */
};

/* Frame (155 bytes) */
static const unsigned char pkt3[155] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x00, 0x8d, 0x00, 0x08, 0x40, 0x00, 0xff, 0x11, /* ....@... */
0x90, 0x1a, 0x0a, 0x00, 0x00, 0x42, 0xe0, 0x00, /* .....B.. */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x79, /* .......y */
0xd4, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* .~...... */
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x5f, /* ......._ */
0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x04, /* printer. */
0x5f, 0x73, 0x75, 0x62, 0x05, 0x5f, 0x68, 0x74, /* _sub._ht */
0x74, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, /* tp._tcp. */
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, /* local... */
0x00, 0x01, 0x08, 0x5f, 0x70, 0x72, 0x69, 0x6e, /* ..._prin */
0x74, 0x65, 0x72, 0x04, 0x5f, 0x73, 0x75, 0x62, /* ter._sub */
0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, /* ._http._ */
0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, /* tcp.loca */
0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, /* l....... */
0x11, 0x93, 0x00, 0x17, 0x04, 0x74, 0x65, 0x73, /* .....tes */
0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x04, /* t._http. */
0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, /* _tcp.loc */
0x61, 0x6c, 0x00                                /* al. */
};

/* Frame (81 bytes) */
static const unsigned char pkt4[81] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0x00, 0x11, /* ..^..... */
0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
0x00, 0x43, 0x00, 0x09, 0x40, 0x00, 0xff, 0x11, /* .C..@... */
0x90, 0x63, 0x0a, 0x00, 0x00, 0x42, 0xe0, 0x00, /* .c...B.. */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x2f, /* ......./ */
0x2f, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* /....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x74, /* .......t */
0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, /* est._htt */
0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, /* p._tcp.l */
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0xff, 0x00, /* ocal.... */
0x01                                            /* . */
};

/* Frame (171 bytes) */
static const unsigned char pkt5[171] = {
0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb, 0xec, 0x17, /* ..^..... */
0x2f, 0xbd, 0xa4, 0xb1, 0x08, 0x00, 0x45, 0x00, /* /.....E. */
0x00, 0x9d, 0x1d, 0xbc, 0x00, 0x00, 0xff, 0x11, /* ........ */
0xf4, 0xe5, 0xc0, 0xa8, 0x07, 0x0a, 0xe0, 0x00, /* ........ */
0x00, 0xfb, 0x14, 0xe9, 0x14, 0xe9, 0x00, 0x89, /* ........ */
0x2c, 0xb0, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, /* ,....... */
0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x04, 0x74, /* .......t */
0x65, 0x73, 0x74, 0x05, 0x5f, 0x68, 0x74, 0x74, /* est._htt */
0x70, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, /* p._tcp.l */
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x21, 0x80, /* ocal..!. */
0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x11, 0x00, /* ....x... */
0x00, 0x00, 0x00, 0x00, 0x50, 0x08, 0x43, 0x61, /* ....P.Ca */
0x74, 0x72, 0x6f, 0x2d, 0x50, 0x43, 0xc0, 0x1c, /* tro-PC.. */
0xc0, 0x0c, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, /* ........ */
0x11, 0x94, 0x00, 0x01, 0x00, 0xc0, 0x33, 0x00, /* ......3. */
0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, /* ......x. */
0x04, 0xc0, 0xa8, 0x07, 0x0a, 0xc0, 0x33, 0x00, /* ......3. */
0x2f, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, /* /.....x. */
0x05, 0xc0, 0x33, 0x00, 0x01, 0x40, 0xc0, 0x0c, /* ..3..@.. */
0x00, 0x2f, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, /* ./.....x */
0x00, 0x09, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x00, /* ........ */
0x80, 0x00, 0x40                                /* ..@ */
};

static MDNS_QUERY_INFO mdns_query_0 = {"test", "_http._tcp", NX_NULL};
static MDNS_QUERY_INFO mdns_query_1 = {NX_NULL, "_http._tcp", "_printer"};

MDNS_TEST_SEQ mdns_query_start_stop[] = {
    {TITLE, "Query start and stop", 20, 0},
    {WAIT, NX_NULL, 0, 5},
    {DUMP, NX_NULL, 0, 0},
    
    /* Add a query*/
    {MDNS_QUERY, (char*)&mdns_query_0, 0, 0},

    /* Check the query packet. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt4[0], sizeof(pkt4), 5},

    /* Delete the query. */
    {MDNS_QUERY_DELETE, NX_NULL, 0, 0},

    /* Reject any queries. */
    {MDNS_REJECT_ANY_V4, NX_NULL, MDNS_FLAG_QUERY, 5},
    
    /* Add a query*/
    {MDNS_QUERY, (char*)&mdns_query_0, 0, 0},

    /* Check the query packet. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt4[0], sizeof(pkt4), 5},

    /* Inject a response. */
    {INJECT, (char*)&pkt5[0], sizeof(pkt5), 0},

    /* Reject any queries. */
    {MDNS_REJECT_ANY_V4, NX_NULL, MDNS_FLAG_QUERY, 5},

    /* Delete the query. */
    {MDNS_QUERY_DELETE, NX_NULL, 0, 0},


    /* Add a query*/
    {MDNS_QUERY, (char*)&mdns_query_1, 0, 0},

    /* Check the query packet. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt1[0], sizeof(pkt1), 5},

    /* Delete the query. */
    {MDNS_QUERY_DELETE, NX_NULL, 0, 0},

    /* Reject any queries. */
    {MDNS_REJECT_ANY_V4, NX_NULL, MDNS_FLAG_QUERY, 5},

    /* Add a query*/
    {MDNS_QUERY, (char*)&mdns_query_1, 0, 0},

    /* Check the query packet. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt1[0], sizeof(pkt1), 5},

    /* Inject a response. */
    {INJECT, (char*)&pkt2[0], sizeof(pkt2), 0},

    /* Check the query packet with known answer. */
    {MDNS_CHECK_DATA_V4, (char*)&pkt3[0], sizeof(pkt3), 5},

    /* Delete the query. */
    {MDNS_QUERY_DELETE, NX_NULL, 0, 0},

    /* Reject any queries. */
    {MDNS_REJECT_ANY_V4, NX_NULL, MDNS_FLAG_QUERY, 5},
    
};

int mdns_query_start_stop_size = sizeof(mdns_query_start_stop) / sizeof(MDNS_TEST_SEQ);

#endif /* __PRODUCT_NETXDUO__  */

